package com.guangyunl.d_var;

public class Demo01Var {
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3, 4, 5};
        sum(arr1);
        sum(2, 3, 4, 5, 6);
        sum1(1, 2,3,4,5,6);
    }

    public static void sum(int...arr){
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("sum = " + sum);
    }

    //参数位置不能连续写多个可变参数，而且当可变参数和其他普通参数一起使用时，可变参数需要放到参数列表最后
    public static void sum1(int a, int...arr){
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("a = " + a);
        System.out.println("sum = " + sum);
    }


}
/*
sum = 15
sum = 20
a = 1
sum = 20
 */